<template>
	<view class="mains box box-tb">
		<u-navbar :is-back="false" title=" " v-show="current == 0 || current ==1" :background="background" :border-bottom="false">
			<view class="slot-wrap">
				<view class="ml20" style="color: #fff;">
					五育通·劳动教育云
				</view>
			</view>
		</u-navbar>
		<u-navbar :is-back="false" title="我的" title-color="#ffff" v-show="current == 2" :background="background" :border-bottom="false"></u-navbar>
		<view class="content">
			<view class="w100" style="height: 100%;" v-show="current == 0 || current == 1">
				<course-view ref="personView" :bjmc="dclass.bjmc" style="height: 100%;"></course-view>
			</view>
			<view class="w100" v-show="current == 2" style="height: 100%;">
				<person-view ref="personViews" style="height: 100%;"></person-view>
			</view>
		</view>
		<u-tabbar v-model="current" :list="list" @change="goIndex" active-color="#4A8CF5" inactive-color="#646D7E" :midButton="true" bg-color="#f1f1fd">
		</u-tabbar>
	</view>
</template>

<script>
	import courseView from './compoents/index/index.vue';
	// import taskView from './compoents/task/task.vue';
	import personView from './compoents/person/person.vue';
	export default {
		components: {
			courseView,
			personView
		},
		data() {
			return {
				user:uni.getStorageSync("user"),
				list: [{
						text: '首页',
						// pagePath: '/pages/home/home',
						iconPath: "/static/tabBar/home.png",
						selectedIconPath: "/static/tabBar/home_act.png",
						customIcon: false,
						color: "#646D7E",
						selectedColor: "#4A8CF5"
					},
					{
						iconPath: "https://cdn.uviewui.com/uview/common/min_button_select.png",
						selectedIconPath: "https://cdn.uviewui.com/uview/common/min_button_select.png",
						text: '',
						// pagePath: '/pages/task/task',
						customIcon: true,
						color: "#4A8CF5",
						selectedColor: "#4A8CF5",
						midButton: true
					},
					{
						iconPath: "/static/tabBar/my.png",
						selectedIconPath: "/static/tabBar/my_act.png",
						text: '我的',
						// pagePath: '/pages/my/my',
						customIcon: false,
						color: "#646D7E",
						selectedColor: "#4A8CF5"
					}
				],
				current: 0,
				background: {
					// background: `url('https://yhykt.oss-cn-beijing.aliyuncs.com/2D5D1A7CF6DC427EBB27F02913576ECEbg.png?Expires=4781594278&OSSAccessKeyId=LTAI4Fgsq7J3XQi7e2SRfzjJ&Signature=42sxp1l%2BEKDaYXDVb0rYvOvF5eY%3D') no-repeat`,
					// height:'297rpx',
					// backgroundImage: 'linear-gradient(90deg, rgb(255, 0, 69), rgb(255, 106, 95))',
					backgroundColor:'#7484f7'
				},
				dclass:''
			}
		},
		onShareAppMessage(res) {
			return {
				title:uni.getStorageSync('fxTitle'),
				path: '/pages/index/share?data=' + encodeURIComponent(JSON.stringify(uni.getStorageSync('chat_info'))),
				imageUrl: uni.getStorageSync('fxImage')
			}
		},
		onShareTimeline(){
			return {
				title:uni.getStorageSync('fxTitle'),
				path: '/pages/index/share?data=' + encodeURIComponent(JSON.stringify(uni.getStorageSync('chat_info'))),
				imageUrl: uni.getStorageSync('fxImage')
			}
		},
		onShow() {
			// //console.log('shiow'+this.current);
			// if(this.current == 0 || this.current ==1){
			// 	this.$refs.personView.bjqlist();
			// }
			if(this.current == 2){
				this.$refs.personViews.setdata()
			}
			if (this.dclass == ``) {
				// //console.log('为获取BJ');
				this.getStuClass();
			}
			if(this.current == 0 ||this.current == 1){
				// //console.log('以获取');
				this.$refs.personView.setData();
			}
		},
		//下拉刷新
		// onPullDownRefresh(){
		// 	if(this.current == 0 || this.current == 1){
		// 		this.$refs.personView.setData();
		// 	}else{
		// 		this.$refs.personViews.setdata()
		// 	}
		// },
		// onReachBottom(e) {
		// 	if(this.current == 0 || this.current == 1){
		// 		this.$refs.personView.fenye();
		// 	}
		// },
		onLoad() {
			// this.getStuClass();
		},
		onPageScroll(res) {
			if(res.scrollTop >= 50){
				this.background.backgroundColor = '#7484f7'
			}else{
				this.background.backgroundColor = '#7484f7'
			}
		},
		methods: {
			getStuClass() {
				let opts = {
					url: '/dclass/getStuClass',
					method: 'post'
				};
				let params = {
					userid: this.user.id
				};
				this.$api.post(opts, params).then(res => {
					//console.log(this.user)
					//console.log(res)
					this.dclass = res.data;
					uni.setStorageSync('dclass',res.data);
					// 设置默认班级
					uni.setStorage({
						key:'dclass',
						data:res.data,
						success: (resp) => {
							this.$refs.personView.setData();
						}
					})
				})
			},
			goIndex(index) {
				if (index == 0) {
					uni.setNavigationBarTitle({
						title: '首页'
					});
					this.$refs.personView.bjqlist();
				} else if (index == 1) {
					uni.navigateTo({
						url: "/stupageHome/pubClassStyle"
					})
				} else {
					this.$nextTick(() => {
						this.$refs.personViews.setdata()
					})
					uni.setNavigationBarTitle({
						title: '我的'
					});
				}
			},
			handleCancel() {
				this.show = false
			},
			pubTask(index) {
				if(index == 0){
					uni.navigateTo({
						url: "/pageHome/pubClassStyle"
					})
				}else if(index == 1){
					uni.navigateTo({
						url: "/pageHome/pubCouseTask"
					})
				}else{
					uni.navigateTo({
						url: "/pageHome/pubSjTask"
					})
				}
				
			},

		}
	}
</script>

<style scoped lang="scss">
	.mains {
		// position: absolute;
		// top: 0;
		// right: 0;
		// left: 0;
		width: 100%;
		height: 100%;
	}
	.content {
		height:100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		/* color: #8f8f94; */
	}

	.bar {
		display: flex;
		align-items: center;
		padding-left: 50rpx;
	}

	.ml50 {
		margin-left: 20rpx;
	}
	.flex-1 {
		flex: 1;
		text-align: center;
		height: 112rpx;
		line-height: 112rpx;
		font-size: 28rpx;
		background: #F8F9FC;
		color: #1C1C1C;
		font-weight: bold;
	}
	
	.pubbar {
		width: 100%;
		padding: 100rpx;
	}
	.title-top {
		padding-left: 76rpx;
		width: 100%;
		text-align: left;
		font-size: 28rpx;
		height: 128rpx;
		line-height: 128rpx;
		border-bottom: 2rpx solid #EEF4F8;
		color: #959AA5;
	}
</style>
